home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / strlib.zip / MEMTRANS.C < prev    next >
Text File  |  1993-01-04  |  2KB  |  47 lines

  1.  
  2. /*  File   : memtrans.c
  3.     Author : Richard A. O'Keefe.
  4.     Updated: 2 June 1984
  5.     Defines: memtrans()
  6.  
  7.     memtrans(dst, src, from, to, len)
  8.     copies exactly len characters from src[] to dst[], translating chars
  9.     in from[] to corresponding characters in to[].   From[] and to[] are
  10.     handled by _str2map. BEWARE: _str2map normally expects characters in
  11.     the range 0..127.  The Vax MOVTC instruction thinks its table is 256
  12.     bytes long; if you want to translate arbitrary bytes you'd better be
  13.     sure that the _map_vec array is 256 bytes long.  As distributed, the
  14.     memtrans function is only for translating ASCII (to 8-bit codes).
  15.  
  16.     The VaxAsm code can only handle 0 <= len < 2^16, and is presented as
  17.     usual for your interest and amusement.  Why *do* designers of 32-bit
  18.     machines put 16-bit limits on strings?  (Dec aren't the only ones.)
  19. */
  20.  
  21. #include "strings.h"
  22. #include "_str2map.h"
  23.  
  24. #if     VaxAsm
  25.  
  26. void memtrans(dst, src, from, to, len)
  27.     _char_ *dst, *src, *from, *to;
  28.     int len;
  29.     {
  30.         _str2map(0, from, to);
  31.         asm("movtc 20(ap),*8(ap),$0,__map_vec,20(ap),*4(ap)");
  32.     }
  33.  
  34. #else  ~VaxAsm
  35.  
  36. void memtrans(dst, src, from, to, len)
  37.     register _char_ *dst, *src;
  38.     _char_ *from, *to;
  39.     register int len;
  40.     {
  41.         _str2map(0, from, to);
  42.         while (--len >= 0) *dst++ = _map_vec[*src++];
  43.     }
  44.  
  45. #endif  VaxAsm
  46.  
  47.